-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Desktop, Mobile: Add Joplin Cloud account information to configuration screen #10553
Desktop, Mobile: Add Joplin Cloud account information to configuration screen #10553
Conversation
website={this.props.settings['sync.10.website']} | ||
styles={this.styles()} | ||
/>, | ||
[emailToNoteDescription(), emailToNoteLabel(), accountEmailLabel(), accountTypeLabel(), accountInformationLabel()], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This way of adding search text for custom components may need to be refactored at some point (though not in this pull request :) ).
One option could be to create a custom <SearchableText>...</SearchableText>
component that sends search text to the settings screen with a custom React context and provider.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now let's put only emailToNoteLabel()
and emailToNoteDescription()
in there
It looks like |
I updated the PR, thanks for the review, Henry! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that JoplinCloudConfig
is now its own component — that should make the mobile settings screen easier to maintain.
I've left a few comments.
packages/app-mobile/components/screens/ConfigScreen/JoplinCloudConfig.tsx
Outdated
Show resolved
Hide resolved
packages/app-mobile/components/screens/ConfigScreen/JoplinCloudConfig.tsx
Outdated
Show resolved
Hide resolved
</View> | ||
<View style={props.styles.styleSheet.settingContainerNoBottomBorder}> | ||
<Text style={props.styles.styleSheet.settingText}>{accountTypeLabel()}</Text> | ||
<Text style={props.styles.styleSheet.settingTextEmphasis}>{accountTypeToString(parseInt(props.accountType, 10))}</Text> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚧 Possible crash 🚧: Be careful here! Currently, accountTypeToString
throws when the account type is unknown. If we eventually add a new account type, this might cause the app to crash if users with this account type open the JoplinCloud config screen on an old client.
Consider including a check that accountType
actually is a valid account type, and displaying 'Unknown'
if not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a function that tries to get the value, if it fails it logs the error message and returns 'Unknown'
, I guess that works, right?
|
packages/app-mobile/components/screens/ConfigScreen/JoplinCloudConfig.tsx
Outdated
Show resolved
Hide resolved
const goToJoplinCloudProfile = async () => { | ||
await bridge().openExternal(`${props.joplinCloudWebsite}/users/me`); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably default to using useCallback
for event handlers, especially when it's dependent on a prop like here. Probably the prop won't change but if for some reason it's initially empty, then set to a value, the component will incorrectly use the empty value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but if for some reason it's initially empty, then set to a value, the component will incorrectly use the empty value
I'm not sure that's true... I think useCallback
prevents unnecessary re-renders of child components (rather than forcing the function to reload). More specifically, suppose that props.joplinCloudWebsite
changes from ""
to "https://joplincloud.com/"
:
props.joplinCloudWebsite
is initially""
. This is the initial render.goToJoplinCloudProfile
is set to a function.props.joplinCloudWebsite
is""
in its scope. As such, ifgoToJoplinCloudProfile
is called, it willopenExternal('/users/me')
.- The component renders. A
Button
is givengoToJoplinCloudProfile
as a prop. This is the first render of thatButton
.
props.joplinCloudWebsite
changes to"https://joplincloud.com/"
. This causes the component to re-render.goToJoplinCloudProfile
is set to a function.props.joplinCloudWebsite
is"https://joplincloud.com/"
in its scope. As such, ifgoToJoplinCloudProfile
is called, it willopenExternal('https://joplincloud.com//users/me')
.- The component renders. A
Button
is givengoToJoplinCloudProfile
as a prop. This prop is different from its previous value (becausefunction(){} !== function(){}
). As a result, theButton
re-renders.- This re-render means that the button will use the new version of
goToJoplinCloudProfile
.
- This re-render means that the button will use the new version of
Observe that in step 2, because React considers different functions to be unequal, the Button
uses the new version of the function that includes "https://joplincloud.com/"
for props.joplinCloudWebsite
in its scope.
Also see react.dev's "Should you add useCallback everywhere".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, that's true, it will re-render anyway.
But I actually think that it's reasonable to default to adding useCallback rather than wondering whether it needs to be optimised or not. In this case maybe it doesn't make a difference that it re-render even when the prop doesn't change, but maybe it does, who knows. That's the idea of mostly defaulting to using useCallback - then we don't need to wonder about this, and it feels like it's more future proof
margin-bottom: calc(var(--joplin-font-size) * 3); | ||
|
||
table { | ||
margin-bottom: calc(var(--joplin-font-size) * 1.5); | ||
border: none; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to avoid these CSS calculations? As I think that will make it difficult to maintain a consistent style throughout the application. We have the --joplin-margin
- could that be enough? Or if something else is needed maybe introduce a new margin?
I updated the PR and the screenshots, thanks for the review! |
enum AccountType { | ||
Default = 0, | ||
Basic = 1, | ||
Pro = 2, | ||
Team = 3, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This AccountType could be used elsewhere, including in joplinCloud.ts so I think this file should be named more generically. Maybe just types.ts.
Even accountTypeToString
is type-related since it converts from one type to another
@pedr, I just looked at the Joplin Cloud screen on mobile and it looks different from all the other screen. Was there any reason why it wasn't implemented like, for example, the "Tools" or "Import and Export" screens? It feels like it wasn't necessary to create a bespoke screen for this unless I'm missing something. The reason we prefer all screens to look the same is that it makes it a lot easier to update the design, which we want to do some day. |
I can see what you mean about having a screen that is implemented differently, and I could try to refactor the content out of the component to the When implementing I tried to find in the config screen another place where we had a pair of key-value that was shown like the But even if I move the content of the screen out of the component to the |
Maybe the |
Can I create an issue to refactor this so we don't forget about it? |
Yes please |
I'm adding Joplin account information to the configuration screen that we have for Joplin Cloud. I'm including the email and account type fields and a link to Joplin Cloud profile.
For Desktop I tried to follow the website design and for mobile I tried to reuse components that are already being used inside the Settings screen.
For the mobile I used the addition of the feature to move all the Joplin Cloud component to its own file.
Desktop
Mobile